package com.lbssoft.gpsbd.dao;

import com.lbssoft.gpsbd.dao.sql.LayerSql;
import com.lbssoft.gpsbd.dao.sql.PoiSql;
import com.lbssoft.gpsbd.model.Layer;
import com.lbssoft.gpsbd.model.LayerPermission;
import com.lbssoft.gpsbd.model.Poi;
import com.lbssoft.gpsbd.model.PoiPermission;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PoiMapper {


	/**
	 * 获取我的兴趣点
	 * @return
     */
	@Select("SELECT t.* FROM lbs_pois t LEFT JOIN lbs_user_poi a ON a.poiId = t.id LEFT JOIN lbs_users b ON b.id = a.userId  WHERE b.id = #{userId} order by id desc")
	List<Poi> list(@Param("userId") long userId);

	/**
	 * 创建兴趣点
	 * @param poi
     */
	@Insert("INSERT INTO lbs_pois(name,type,area,styles,visible) VALUE(#{name},#{type},#{area},#{styles},1)")
	@Options(useGeneratedKeys=true, keyProperty="id")
	void add(Poi poi);

	/**
	 * 创建用户兴趣点关系
	 * @param poiPermission
	 */
	@Insert("INSERT INTO lbs_user_poi(userId,poiId) VALUES(#{userId},#{poiId})")
	void addUserPoi(PoiPermission poiPermission);

	/**
	 * 删除兴趣点
	 * @param id
     */
	@Delete("DELETE FROM lbs_pois where id = #{id} ")
	void delete(@Param("id") int id);

	/**
	 * 更新兴趣点信息
	 */
	@UpdateProvider(type = PoiSql.class, method = "update")
	void update(Poi poi);

}
